package model

import (
	"github.com/g42cloud-sdk/g42cloud-sdk-go/core/utils"

	"errors"
	"github.com/g42cloud-sdk/g42cloud-sdk-go/core/converter"

	"strings"
)

type PrePaidServerEipBandwidth struct {
	Size *int32 `json:"size,omitempty"`

	Sharetype PrePaidServerEipBandwidthSharetype `json:"sharetype"`

	Chargemode *string `json:"chargemode,omitempty"`

	Id *string `json:"id,omitempty"`
}

func (o PrePaidServerEipBandwidth) String() string {
	data, err := utils.Marshal(o)
	if err != nil {
		return "PrePaidServerEipBandwidth struct{}"
	}

	return strings.Join([]string{"PrePaidServerEipBandwidth", string(data)}, " ")
}

type PrePaidServerEipBandwidthSharetype struct {
	value string
}

type PrePaidServerEipBandwidthSharetypeEnum struct {
	PER   PrePaidServerEipBandwidthSharetype
	WHOLE PrePaidServerEipBandwidthSharetype
}

func GetPrePaidServerEipBandwidthSharetypeEnum() PrePaidServerEipBandwidthSharetypeEnum {
	return PrePaidServerEipBandwidthSharetypeEnum{
		PER: PrePaidServerEipBandwidthSharetype{
			value: "PER",
		},
		WHOLE: PrePaidServerEipBandwidthSharetype{
			value: "WHOLE",
		},
	}
}

func (c PrePaidServerEipBandwidthSharetype) Value() string {
	return c.value
}

func (c PrePaidServerEipBandwidthSharetype) MarshalJSON() ([]byte, error) {
	return utils.Marshal(c.value)
}

func (c *PrePaidServerEipBandwidthSharetype) UnmarshalJSON(b []byte) error {
	myConverter := converter.StringConverterFactory("string")
	if myConverter == nil {
		return errors.New("unsupported StringConverter type: string")
	}

	interf, err := myConverter.CovertStringToInterface(strings.Trim(string(b[:]), "\""))
	if err != nil {
		return err
	}

	if val, ok := interf.(string); ok {
		c.value = val
		return nil
	} else {
		return errors.New("convert enum data to string error")
	}
}
